package solutions.contest.week272;

import solutions.lib.BaseSolution;

/**
 * @author lizhidong
 * <a href="https://leetcode-cn.com/contest/weekly-contest-272/problems/adding-spaces-to-a-string/">2109.向字符串添加空格</a>
 */
public class Solution2109 extends BaseSolution {

    public String addSpaces(String s, int[] spaces) {
        StringBuilder stringBuilder = new StringBuilder();
        int p1 = 0, p2 = 0, len = s.length(), n = spaces.length;
        while (p1 < len) {
            if (p2 < n && p1 == spaces[p2]) {
                stringBuilder.append(' ');
                p2++;
            }
            stringBuilder.append(s.charAt(p1++));
        }
        while (p2++ < n) {
            stringBuilder.append(' ');
        }
        return stringBuilder.toString();
    }

    public static void main(String[] args) {
        Solution2109 solution = new Solution2109();
        System.out.println(solution.addSpaces("helloworld", new int[] {
                5, 10
        }));
    }
}